﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.Sockets.Core;

namespace Pixysoft.Framework.Sockets.Controller
{
    class MessageController : IMessageFactory
    {
        private static volatile MessageController instance;

        private static object syncRoot = new Object();

        public static MessageController Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                        {
                            instance = new MessageController();
                        }
                    }
                }
                return instance;
            }
        }

        public IProtocolMessage CreateMessage(int protocol, int action)
        {
            IProtocolMessage message = new ProtocolMessage();
            message.Protocol = protocol;
            message.Action = action;
            return message;
        }

        public IProtocolMessage CreateMessage(IProtocolHeader header)
        {
            IProtocolMessage message = new ProtocolMessage();
            message.Protocol = header.Protocol;
            message.Action = header.Action;
            message.Sn = header.Sn;
            message.Status = header.Status;
            return message;
        }
    }
}
